package com.test.action;

import com.opensymphony.xwork2.ActionContext;
import com.test.base.BaseAction;
import com.test.domain.User;

public class LoginoutAction extends BaseAction<User> {
	private static final long serialVersionUID = 1L;
	public String loginUI(){
		return "loginUI";
	}
	public String login(){
		//因为后面要用到Md5进行加密处理，如果传过去的值为空（直接调用这个方法，就是绕过loginUI,在地址栏直接输入loginout_login）,
		//会报空指针异常。
		if(model.getPassword()==null){
			return "toHome";
		}
		User user = userService.findLoginUser(model.getLoginName(),model.getPassword());
		if(user == null){
			addFieldError("login_error", "用户名或密码不正确");
			return "loginUI";
		}else{
			ActionContext.getContext().getSession().put("user", user);	
			return "toHome";
		}
	}
	public String logout(){
		ActionContext.getContext().getSession().remove("user");
		return "logout";
	}
}
